Skip to content

feat: using dpf instead of reader in "results" module #1300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 340 commits into
base: main
Choose a base branch
from

Conversation

germa89
Copy link
Collaborator

@germa89 germa89 commented Jul 27, 2022

(Most of the general info has been moved to #4084)

Migrate most of the backend and set the foundations for following PRs. Aiming to migrate most of the numerical methods. Plotting will be in a follow up PR.

To migrate

Missing

To be done in follow up PRs

Done

  • available_results
  • element_components
  • element_lookup
  • element_stress
  • filename
  • n_results
  • n_sector
  • nodal_acceleration
  • nodal_displacement
  • nodal_elastic_strain
  • nodal_plastic_strain
  • nodal_reaction_forces
  • nodal_solution
  • nodal_static_forces
  • nodal_stress
  • nodal_temperature
  • nodal_thermal_strain
  • nodal_time_history
  • nodal_velocity
  • node_components
  • parse_step_substep
  • pathlib_filename
  • principal_nodal_stress
  • time_values
  • version

To not migrate.

A NotImplementedError will be raised.

  • text_result_table Used for the text in the plots. Not porting it.
  • write_tables: Write binary tables to ASCII.
  • read_record: Read a record from the opened file. Records are hidden in DPF.
  • overwrite_element_solution_record: DPF cannot write solution files.
  • overwrite_element_solution_records: DPF cannot write solution files.
  • cs_4x4 - I couldn't make it work locally, so I'm not porting it. It will raise a not implemented error.
  • solution_info
    It doesn't make sense to be ported at the moment.
     >>> rst.solution_info(0)
            {'cgcent': [],
             'fatjack': [],
             'timfrq': 44.85185724963714,
             'lfacto': 1.0,
             'lfactn': 1.0,
             'cptime': 3586.4873046875,
             'tref': 71.6,

There are many methods which are duplicate from mapdl.post_processing, I will probably redirect one to another (I don't know which one should prevail, probably post-processing).

DPFResult class should provide a way to manipulate RST files without having an MAPDL instance alive.

Full list of Reader class methods

The complete lists of functions in that class are:

Show full list of Result class functions

ELEMENT_INDEX_TABLE_KEYS
ELEMENT_RESULT_NCOMP
__annotations__
__class__
__del__
__delattr__
__dict__
__dir__
__doc__
__eq__
__format__
__ge__
__getattribute__
__gt__
__hash__
__init__
__init_subclass__
__le__
__lt__
__module__
__ne__
__new__
__reduce__
__reduce_ex__
__repr__
__setattr__
__sizeof__
__str__
__subclasshook__
__weakref__
_animate_point_scalars
_animate_time_solution
_bc_header
_cfile
_element_map
_element_solution_header
_extract_element_components
_extract_node_components
_extract_surface_element_result
_is_cyclic
_is_distributed
_is_main
_is_thermal
_load_element_table
_load_materials
_load_section_data
_map_flag
_nodal_result
_nodal_solution_result
_nodfor
_nodstr
_plot_nodal_result
_plot_point_scalars
_read_components
_read_result_header
_result_nitem
_result_pointers
_result_solution_header
_result_solution_header_ext
_solution_header
_store_mesh
animate_nodal_displacement
animate_nodal_solution
animate_nodal_solution_set
available_results
cs_4x4
cylindrical_nodal_stress
element_components
element_lookup
element_solution_data
element_stress
filename
materials
mesh
n_results
n_sector
nodal_acceleration
nodal_boundary_conditions
nodal_displacement
nodal_elastic_strain
nodal_input_force
nodal_plastic_strain
nodal_reaction_forces
nodal_solution
nodal_static_forces
nodal_stress
nodal_temperature
nodal_thermal_strain
nodal_time_history
nodal_velocity
node_components
overwrite_element_solution_record
overwrite_element_solution_records
parse_coordinate_system
parse_step_substep
pathlib_filename
plot
plot_cylindrical_nodal_stress
plot_element_result
plot_nodal_displacement
plot_nodal_elastic_strain
plot_nodal_plastic_strain
plot_nodal_solution
plot_nodal_stress
plot_nodal_temperature
plot_nodal_thermal_strain
plot_principal_nodal_stress
principal_nodal_stress
read_record
result_dof
save_as_vtk
section_data
solution_info
text_result_table
time_values
version
write_tables

Notes


Summary by Sourcery

Replace the legacy reader‐based results interface with a new DPF backend: introduce a global switch to toggle backends, implement and expose the DPFResult class with migrated public APIs using ansys-dpf-core, update test infrastructure and CI workflows to support DPF testing, and refine misc, launcher, and pytest utilities to accommodate the change.

New Features:

  • Introduce a DPF-based result backend controlled by a new use_reader_backend switch in MAPDL.
  • Add a new DPFResult class under ansys.mapdl.core.reader.result migrating public result APIs to use ansys-dpf-core.
  • Expose utility functions get_ip and parse_ip_route for IP detection and switch GRPC/Docker connection logic.

Bug Fixes:

  • Strip whitespace from output of MapdlGrpc.sys and clarify assertion error when reusing MAPDL instances.

Enhancements:

  • Improve pytest reporting by truncating long messages and wrapping lines, and include PYMAPDL_ADDITIONAL_SWITCHES in headers.
  • Enhance mapdl.result file‐path handling to create isolated temp directories and enrich FileNotFoundError messages.
  • Refactor IP‐route parsing and unify _parse_ip_route usage in launcher and misc modules.

CI:

  • Introduce TEST_DPF_BACKEND environment variable in CI workflows to enable/disable DPF tests.

Documentation:

  • Add a changelog entry for the new DPF‐based results module.

Tests:

  • Add comprehensive DPFResult tests in tests/test_result.py and update fixtures for test_dpf_backend.
  • Adjust tests/conftest.py, tests/common.py, and test launcher to integrate DPF backend testing.

Summary by Sourcery

Migrate the "results" module to use ansys-dpf-core by introducing a new DPFResult class and a global use_reader_backend switch, update MAPDL core to support both backends, refine error handling and temporary file management, and extend CI workflows and tests to validate the new DPF-based implementation.

New Features:

  • Introduce DPFResult class to replace legacy reader-based result interface using ansys-dpf-core
  • Add use_reader_backend switch in MAPDL to toggle between DPF and legacy reader backends
  • Expose get_local_ip and parse_ip_route utilities for DPF server connection handling

Enhancements:

  • Improve mapdl.result to download to isolated temporary directories and provide clearer FileNotFoundError messages
  • Strip whitespace from mapdl.sys output and enforce type annotations
  • Refactor CI test arguments for reproducibility and set default random-order seeds
  • Streamline log_test fixture and unify usage of mapdl.com in testing utilities

CI:

  • Add TEST_DPF_BACKEND environment variable to CI to enable/disable DPF tests
  • Update .ci/start_mapdl.sh, entrypoint, and GitHub workflows to optionally launch DPF server and collect DPF logs
  • Adjust container entrypoint to manage DPF server startup and container ports

Documentation:

  • Add changelog entry for DPF-based results module

Tests:

  • Add comprehensive tests for DPFResult functionality and compatibility against legacy reader and MAPDL-Post
  • Extend test_mapdl to validate result backend selection and types
  • Introduce test_dpf_backend flag in conftest to conditionally run DPF tests

@germa89 germa89 self-assigned this Jul 27, 2022
@codecov
Copy link

codecov bot commented Aug 5, 2022

Codecov Report

Attention: Patch coverage is 1.42631% with 622 lines in your changes missing coverage. Please review.

Project coverage is 87.30%. Comparing base (a9d37dc) to head (0829f58).
Report is 4 commits behind head on main.

❌ Your patch check has failed because the patch coverage (1.42%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1300      +/-   ##
==========================================
- Coverage   91.82%   87.30%   -4.53%     
==========================================
  Files         187      189       +2     
  Lines       15033    15663     +630     
==========================================
- Hits        13804    13674     -130     
- Misses       1229     1989     +760     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@akaszynski
Copy link
Collaborator

Fundamentally, this all needs to be moved to DPF-Post and DPF post needs to have an even simpler API.

Right now we have:

  • DPF-Core
  • DPF-Post
  • MAPDL-Post
  • Legacy reader

I'd rather not make a 5th. There's a potential new hire that will work for the PyAnsys team on DPF-Post and I'd like him to work on this along with you.

@germa89
Copy link
Collaborator Author

germa89 commented Feb 22, 2023

On-hold for the moment until I see how pydpf-post develops.

@germa89 germa89 added the DO NOT MERGE Not ready to be merged yet label Jul 17, 2024
@germa89
Copy link
Collaborator Author

germa89 commented Aug 27, 2024

Closing because I do not have the capacity for this. I think eventually we should use dpf-post for this.

@germa89 germa89 closed this Aug 27, 2024
@germa89 germa89 mentioned this pull request Mar 24, 2025
31 tasks
@germa89 germa89 reopened this May 20, 2025
@germa89
Copy link
Collaborator Author

germa89 commented May 20, 2025

We are so back...

@germa89 germa89 changed the title Removing Reader dependency in Results module feat: using dpf instead of reader in "results" module May 20, 2025
@github-actions github-actions bot added the new feature Request or proposal for a new feature label May 20, 2025
@germa89
Copy link
Collaborator Author

germa89 commented May 22, 2025

For the testing of this PR I am testing the three of all... PyMAPDL-Reader (Reader), PyMAPDL-Post (Post) and DPF-Core (DPF).

I would have thought that it should be straight forward...

image

But it seems the Reader shows different results in many cases, mainly related with results not available (or equal to zero):

FAILED tests/test_result.py::TestPinchedCylinderVM6::test_result_in_element_coordinate_system[2] - AssertionError: Reader shows different results to DPF and MAPDL-Post. Showing the post-reader error

Not equal to tolerance rtol=1e-05, atol=1e-08

Mismatched elements: 64 / 64 (100%)
Max absolute difference among violations: 1906.65068817
Max relative difference among violations: 1.
 ACTUAL: array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
 DESIRED: array([-957.551804, -954.352829, -948.243362, -943.231461, -950.417862,
       -954.950027, -791.04631 , -239.473806, -835.156525, -833.31424 ,
       -830.457886, -830.36319 , -843.354233, -855.656952, -717.461243,...
FAILED tests/test_result.py::TestPinchedCylinderVM6::test_compatibility_element_stress[2] - AssertionError: Reader shows different results to DPF and MAPDL-Post. Showing the post-reader error

Not equal to tolerance rtol=1e-05, atol=1e-08

Mismatched elements: 64 / 64 (100%)
Max absolute difference among violations: 2729.35662842
Max relative difference among violations: 1.68196902
 ACTUAL: array([-7.655771e+01, -7.409662e+01, -6.887186e+01, -6.074747e+01,
       -5.027208e+01, -3.829016e+01, -2.279749e+01, -2.538273e+00,
       -6.694261e+01, -6.285681e+01, -5.539421e+01, -4.590857e+01,...
 DESIRED: array([-957.551804, -954.352829, -948.243362, -943.231461, -950.417862,
       -954.950027, -791.04631 , -239.473806, -835.156525, -833.31424 ,
       -830.457886, -830.36319 , -843.354233, -855.656952, -717.461243,...

Hence, I am introducing EXIGENT switch on the test_results.py file so I can discard the reader differences if EXIGENT is False, meaning that if the Post and DPF results agree, we are good to go.

When EXIGENT is False, DPF and Post match all the results for all the tests match.

These are sort of preliminary tests on a not-yet ready DPF-based Result API, but I am happy with the progress so far.

Full pytest report on exigent mode

test_dpf_exigent.txt

@germa89 germa89 mentioned this pull request Jul 14, 2025
10 tasks
@germa89 germa89 mentioned this pull request Jul 14, 2025
10 tasks
germa89 added a commit that referenced this pull request Jul 14, 2025
feat: enhance log_test functionality and add test_dpf_backend function before #1300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/CD Related with CICD, Github Actions, etc DO NOT MERGE Not ready to be merged yet maintenance General maintenance of the repo (libraries, cicd, etc) new feature Request or proposal for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants